package com.libraryManage.service.impl;

import com.github.pagehelper.util.StringUtil;
import com.libraryManage.commons.utils.MVCUtil;
import com.libraryManage.commons.utils.PageUtil;
import com.libraryManage.commons.utils.ResponseEntity;
import com.libraryManage.mapper.DictionaryMapper;
import com.libraryManage.service.DictionaryService;
import com.libraryManage.vo.DicBookSortVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @CreateDate 2021-01-31
 * @Author yufang
 */
@Service
public class DictionaryServiceImpl implements DictionaryService {

    @Autowired
    private DictionaryMapper dictionaryMapper;

    /**
     * 获取图书类别字典
     * @param vo
     * @return
     */
    @Override
    public ResponseEntity<List<DicBookSortVo>> getDicBookSortList(DicBookSortVo vo) {
        PageUtil.startPage(vo);
        List<DicBookSortVo> list = dictionaryMapper.getDicBookSortList(vo);
        return PageUtil.tranferPage(list);
    }

    /**
     * 更新图书类别
     * @param vo
     * @return
     */
    @Override
    public ResponseEntity<List<DicBookSortVo>> updateDicBookSort(DicBookSortVo vo) {

        //1.更新图书类别
        if(!StringUtils.isEmpty(vo)){
            dictionaryMapper.updateDicBookSort(vo);
        }
        //2.刷新用户界面内容
        return getDicBookSortList(vo);

    }

    /**
     * 删除图书类别
     * @param id
     * @return
     */
    @Override
    public ResponseEntity<List<DicBookSortVo>> deleteDicBookSort(int id) {

        //1.删除图书类别
        dictionaryMapper.deleteDicBookSort(id);
        //2.刷新用户界面内容,初始化分页内容
        DicBookSortVo dicBookSortVo = new DicBookSortVo();
        dicBookSortVo.setPageSize(5);
        dicBookSortVo.setPageNum(1);
        return getDicBookSortList(dicBookSortVo);


    }

    /**
     * 新增图书类别
     * @param vo
     * @return
     */
    @Override
    public ResponseEntity<List<DicBookSortVo>> createDicBookSort(DicBookSortVo vo) {
        //1.新增图书类别
        if(!StringUtils.isEmpty(vo)) {
            dictionaryMapper.createDicBookSort(vo);
        }
        //2.刷新用户界面内容
        return getDicBookSortList(vo);
    }

}
